package listener;

import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;

@WebListener
public class MyListener01  implements ServletRequestAttributeListener {
    @Override
    public void attributeAdded(ServletRequestAttributeEvent event) {
        // 当向ServletRequest中添加属性时执行的操作
        HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
        System.out.println("添加名称:"+event.getName()+"，值："+event.getValue());
        // 其他处理逻辑
    }
    @Override
    public void attributeRemoved(ServletRequestAttributeEvent event) {
        // 当从ServletRequest中移除属性时执行的操作
        HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
        System.out.println("移除名称"+event.getName()+"，值："+event.getValue());
    }
    @Override
    public void attributeReplaced(ServletRequestAttributeEvent event) {
        // 当替换ServletRequest中的属性时执行的操作
//        HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
//        System.out.println("替换名称：" +request.getAttribute(event.getName()));
    }
}
